package com.chase.framerwork.message;

import com.chase.framerwork.util.StringUtil;

/**
 * 消息提醒
 * 
 * @Author Chase
 * @Date 2013-11-9
 */
public class MessageUtil
{
	private static final ThreadLocal<Message> threadLocal = new ThreadLocal<Message>();

	public static Message set(String code, String info)
	{
		Message message = new Message(code, info);

		threadLocal.set(message);
		return message;
	}

	public static Message setInfo(String info)
	{
		Message message = new Message();
		message.setInfo(info);

		threadLocal.set(message);
		return message;
	}

	public static Message setCode(String code)
	{
		Message message = new Message();
		message.setCode(code);

		threadLocal.set(message);
		return message;
	}

	public static Message get()
	{
		Message message = threadLocal.get();
		if (message == null)
		{
			message = new Message();
		}

		return message;
	}

	public static boolean isEmpty()
	{
		if (StringUtil.isEmpty(getInfo()) && StringUtil.isEmpty(getCode()))
		{
			return true;
		}
		return false;
	}

	public static String getInfo()
	{
		return get().getInfo();
	}

	public static String getCode()
	{
		return get().getCode();
	}

	public static void remove()
	{
		threadLocal.remove();
	}

}
